package com.kukudexin;

import java.io.*;
import java.net.Socket;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/21 13:33
 * @description: tcp客户端
 */
public class TCPClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        OutputStream os = socket.getOutputStream();
        os.write("你好服务器！".getBytes());
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = in.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }

//        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    }
}
